import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
/**
 * 动态路由
 */
export const asyncRoutes = [{
  path: '/login',
  name: 'login',
  component: () => import('@/views/login'),
  hidden: true
}, {
  path: '/404',
  name: '404',
  component: () => import('@/views/404'),
  hidden: true
}, {
  path: '/',
  name: 'home',
  component: Layout,
  redirect: '/index',
  meta: { title: '首页', icon: 'home-o' },
  children: [{
    path: 'index',
    name: 'homeIndex',
    component: () => import('@/views/home'),
    meta: { title: '首页', activeMenu: 'home' }
  }]
}, {
  path: '/pay',
  component: Layout,
  redirect: '/pay/cashier',
  name: 'pay',
  meta: { title: '支付系统', icon: 'bill-o' },
  children: [{
    path: 'cashier',
    name: 'payCashier',
    component: () => import('@/views/pay/cashier'),
    meta: { title: '收银台', activeMenu: 'pay' }
  }, {
    path: 'result',
    name: 'payResult',
    hidden: true,
    component: () => import('@/views/pay/result'),
    meta: { title: '支付结果', activeMenu: 'pay' }
  }]
}, {
  path: '/addressBook',
  component: Layout,
  redirect: '/addressBook',
  name: 'addressBook',
  meta: { title: '通讯录', icon: 'newspaper-o' },
  children: [{
    path: '',
    name: 'addressBookIndex',
    component: () => import('@/views/mailList/index'),
    meta: { title: '通讯录', activeMenu: 'addressBook' }
  }, {
    path: 'details/:id',
    name: 'addressBookDetails',
    component: () => import('@/views/mailList/details'),
    meta: { title: '通讯录详情', activeMenu: 'addressBook' }
  }]
}, {
  path: '/my',
  component: Layout,
  redirect: '/my',
  name: 'my',
  meta: { title: '个人中心', icon: 'manager-o' },
  children: [{
    path: '',
    name: 'myIndex',
    component: () => import('@/views/my/index'),
    meta: { title: '个人中心', activeMenu: 'my' }
  }]
}/*, {
  path: '*',
  redirect: '/404',
  hidden: true
}*/]

const createRouter = () => new Router({
  // mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: asyncRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
